if [ -d ~/Ascend/ascend-toolkit/set_env.sh ]
then
    source ~/Ascend/ascend-toolkit/set_env.sh
elif [ -d /usr/local/Ascend/ascend-toolkit/set_env.sh ]
then
    source /usr/local/Ascend/ascend-toolkit/set_env.sh
fi

export RT_INC=${ASCEND_TOOLKIT_HOME}/runtime/include
export RT_LIB=${ASCEND_TOOLKIT_HOME}/runtime/lib64

# 功能：Host & Device代码混合编译，生成可执行文件,仅需链接libruntime.so
# 编译选项--cce-soc-version和--cce-soc-core-type指的是编译AscendXXXYY上的Vector核程序
include_path=`pwd`/include
output_file=`pwd`/lib/$2
tiling_path=`pwd`/src/tiling
src_files=`ls $1`
tiling_files=`ls ${tiling_path}`

cd $1
bisheng -xcce -O2 \
--cce-aicore-arch=dav-m300 \
-I$RT_INC \
-L$RT_LIB \
-lascendcl \
-lruntime \
-o $output_file \
--shared \
-fPIC \
-I${include_path} \
-I${ASCEND_TOOLKIT_HOME}/compiler/tikcpp/tikcfw/ \
-I${ASCEND_TOOLKIT_HOME}/compiler/tikcpp/tikcfw/impl \
-I${ASCEND_TOOLKIT_HOME}/compiler/tikcpp/tikcfw/interface \
--std=c++17 \
${src_files}

cd ${tiling_path}
c++ \
-I${ASCEND_TOOLKIT_HOME}/include
